package com.paradogs.framework.core.utils;

import io.netty.channel.Channel;

import java.net.InetAddress;
import java.net.InetSocketAddress;

/**
 * @author: yumi
 * @date: 2023/11/24  16:28
 * @Description: TODO
 */
public class IPUtils {

    public static InetSocketAddress getAddr(Channel channel) {
        return (InetSocketAddress) channel.remoteAddress();
    }

    public static String getHost(Channel channel) {
        InetSocketAddress addr = getAddr(channel);
        if (addr == null) {return null;}
        return addr.getHostString();
    }

    public static Integer getPort(Channel channel) {
        InetSocketAddress addr = getAddr(channel);
        if (addr == null) {return null;}
        return addr.getPort();
    }

}
